package com.aigou.admin.aigouspringboot.controller.user;

import com.aigou.admin.aigouspringboot.entity.User;
import com.aigou.admin.aigouspringboot.entity.vo.UserVO;
import com.aigou.admin.aigouspringboot.result.Result;
import com.aigou.admin.aigouspringboot.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Author Mr.LiFuXing
 * @Date 2024/12/17 15:22
 * @Title UserController
 * @Package com.aigou.admin.aigouspringboot.controller.user
 */

@RestController("userUserController")
@RequestMapping
@Slf4j
public class UserController {

    @Resource
    private UserService userService;


    @PostMapping("/user/register")
    public Result register(@RequestBody User user){

        int i = userService.register(user);
        return i>0 ? Result.success():Result.error();

    }

    @PostMapping("/login")
    public Result<UserVO> login(@RequestBody User user, HttpServletRequest httpServletRequest){

        UserVO loginUser = userService.userLogin(user,httpServletRequest);
        return Result.success(loginUser);
    }

    @GetMapping("/user/info")
    public Result<User> getUserInfo(HttpServletRequest request){

        User user = (User) request.getSession().getAttribute("user");
        return Result.success(user);
    }


}
